package com.ctshk.app.train.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.train.req.CacheSetReq;
import com.ctshk.rpc.train.service.ITrainProductAppAndPcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 火车产品表 前端控制器
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-03-11
 */
@Api(value="资源中心-火车产品接口", tags="资源中心-火车产品接口")
@RestController
@RequestMapping("/train-product/cache")
public class TrainProductCacheController extends BaseController {

    @DubboReference
    private ITrainProductAppAndPcService trainProductAppService;

    @ApiOperation(value="火车票订单-缓存-初始化", notes="火车票订单-缓存-初始化")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "火车票订单-缓存-初始化", operDesc = "火车票订单-缓存-初始化")
    @GetMapping("/init")
    public Result lineInit() {
        return trainProductAppService.trainCacheInit();
    }

    @ApiOperation(value="火车票订单-缓存-按时间更新", notes="火车票订单-缓存-按时间更新")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "火车票订单-缓存-按时间更新", operDesc = "火车票订单-缓存-按时间更新")
    @GetMapping("/update/bytime")
    public Result busCacheUpdateByTime() {
        return trainProductAppService.trainCacheUpdateByTime();
    }

    @ApiOperation(value="火车票订单-缓存-按火车车次id更新", notes="火车票订单-缓存-按火车车次id更新")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "火车票订单-缓存-按火车车次id更新", operDesc = "火车票订单-缓存-按火车车次id更新")
    @PostMapping("/update/byid")
    public Result busCacheUpdateById(@RequestBody @NotNull List<Long> ids) {
        return trainProductAppService.trainCacheUpdateById(ids);
    }

    @ApiOperation(value="火车票订单-缓存-剩余票数操作", notes="火车票订单-缓存-剩余票数操作")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "火车票订单-缓存-剩余票数操作", operDesc = "火车票订单-缓存-剩余票数操作")
    @PostMapping("/remain/update")
    public Result remainderNumberUpdate(@RequestBody @Valid CacheSetReq req) {
        return trainProductAppService.remainderNumberUpdate(req);
    }

    @ApiOperation(value="火车站点-缓存-初始化", notes="火车站点-缓存-初始化")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "火车站点-缓存-初始化", operDesc = "火车站点-缓存-初始化")
    @GetMapping("/station/init")
    public Result stationInit() {
        return trainProductAppService.stationInit();
    }
    
}
